// import { useUserStore } from "@/store/modules/user";

/**
 * v-hasPermi 操作权限处理
 * el：dom
 * binding：权限参数
 */

const hasPermi = {
  // 指令的生命周期钩子函数
  mounted(el: any, binding: any) {
    // const store = useUserStore();
    const { value } = binding // 传递的权限数组
    const permissions: any[] = []
    // const permissions = store.permissions;

    if (value && value instanceof Array && value.length > 0) {
      const hasPermissions = permissions.some((permission) => {
        return value.includes(permission)
      })
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}

export default hasPermi
